/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package VoiceIdent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import model.Database;
/**
 *
 * @author JArik
 */
public class VoiceFunctions {

    public static boolean saveVoiceData(ArrayList<VoiceData> vD)
            throws SQLException, FileNotFoundException, IOException
    {
        File fl = new File("_voiceData");
        fl.createNewFile();
        FileOutputStream fos = fos = new FileOutputStream(fl);
        ObjectOutputStream out = out = new ObjectOutputStream(fos);
        out.writeObject(vD);
        out.close();
        fos.close();
        new File("voiceData.backup").delete();
        new File("voiceData").renameTo(new File("voiceData.backup"));
        return fl.renameTo(new File("voiceData"));

        /*
        Database db = new Database();
        String query = "INSERT testName, voicePrint INTO voiceprints ";
        for(int i=0; i<vD.size(); i++)
        {
            VoiceData v = vD.get(i);
            query += "VALUES("+v.getUserName()+",";
        }
        ResultSet set = db.insertDBInfo(query);
        */
    }

    public static ArrayList<VoiceData> loadVoiceData(String filename)
            throws FileNotFoundException, IOException, ClassNotFoundException
    {
        File fl = new File(filename);
        FileInputStream fis =  new FileInputStream(fl);
        ObjectInputStream in = new ObjectInputStream(fis);
        ArrayList<VoiceData> res = (ArrayList<VoiceData>) in.readObject();
        in.close();
        fis.close();
        return res;
    }

}








